package com.zhang.gulimall.ware.service.impl;

import com.zhang.gulimall.ware.entity.PurchaseEntity;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhang.gulimall.common.utils.PageUtils;
import com.zhang.gulimall.common.utils.Query;

import com.zhang.gulimall.ware.dao.PurchaseDetailDao;
import com.zhang.gulimall.ware.entity.PurchaseDetailEntity;
import com.zhang.gulimall.ware.service.PurchaseDetailService;


@Service("purchaseDetailService")
public class PurchaseDetailServiceImpl extends ServiceImpl<PurchaseDetailDao, PurchaseDetailEntity> implements PurchaseDetailService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<PurchaseDetailEntity> page = this.page(
                new Query<PurchaseDetailEntity>().getPage(params),
                new QueryWrapper<>()
        );

        return new PageUtils(page);
    }

    @Override
    public PageUtils queryPageByParams(Map<String, Object> params) {
        QueryWrapper<PurchaseDetailEntity> wrapper = new QueryWrapper<>();
        String wareId = (String) params.get("wareId");
        String status = (String) params.get("status");
        String key = (String) params.get("key");
        if (!wareId.isEmpty()){
            wrapper.lambda().eq(PurchaseDetailEntity::getWareId,wareId);
        }
        if (!status.isEmpty()){
            wrapper.lambda().eq(PurchaseDetailEntity::getStatus,status);
        }
        if (!key.isEmpty()){
            wrapper.and((w)-> w.lambda().eq(PurchaseDetailEntity::getSkuId,key)
                    .or().eq(PurchaseDetailEntity::getPurchaseId,key));
        }
        IPage<PurchaseDetailEntity> page = this.page(
                new Query<PurchaseDetailEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }

}